package cn.edu.neusoft.wuguangsheng.flowerimpression.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.GoodsInfoActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.GoodsBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.service.Service;

public class GoodAdapter extends BaseAdapter<GoodsBean>{

    public GoodAdapter(Context context, List<GoodsBean> items, int layoutResource){
        super(context, items, layoutResource);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView= LayoutInflater.from(context).inflate(layoutResourse,parent,false);
        GoodsInfoViewHolder viewHolder = new GoodsInfoViewHolder(itemView);
        return viewHolder;
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        GoodsInfoViewHolder viewHolder=(GoodsInfoViewHolder) holder;
        GoodsBean goodsBean=items.get(position);

        final String goodname = goodsBean.getGood_name();
        final String goodid = goodsBean.getGood_id();
        final String goodintro = goodsBean.getGood_intro();
        final double goodprice = goodsBean.getGood_price();
        final String img = Service.BASE_URL+"flower_impression/public/uploads/"+goodsBean.getGood_photo();

        viewHolder.goodsitem_name.setText(goodname);
        viewHolder.goodsitem_intro.setText(goodintro);
        viewHolder.goodsitem_time.setText("￥"+String.valueOf(goodprice));
        Picasso.with(context).load(img).into(viewHolder.goodsitem_img);



        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, GoodsInfoActivity.class);
                intent.putExtra("goodid",goodid);
                context.startActivity(intent);

            }
        });
    }

}

